var t = require("../../../mybehaviors/location/location"), a = getApp();

Page({
    behaviors: [ t ],
    data: {
        info: {},
        group_code: {},
        longitude: "",
        latitude: "",
        showOne: !1,
        showTwo: !1,
        shareBox: !1,
        openAuthData: null,
        showAuthDialog: !1
    },
    onLoad: function(t) {
        var e = this;
        try {
            wx.removeStorageSync("applyaddresspoint");
        } catch (t) {}
        this._getLocation(function(t, a) {
            console.log(a.lng), e.setData({
                longitude: a.lng,
                latitude: a.lat
            }), e.getData();
        }), t.id && this.setData({
            id: t.id
        }), t.label && this.setData({
            label: t.label
        }), t.mid && a._setMid(t.mid);
    },
    onShow: function() {
        try {
            var t = wx.getStorageSync("applyaddresspoint");
            console.log(t), t && (console.log(t), this.setData({
                longitude: t.point.lng,
                latitude: t.point.lat
            }));
        } catch (t) {
            console.log(t);
        }
    },
    shareBox: function(t) {
        wx.showLoading({
            title: "加载中"
        });
        var e = this, o = a.getNetAddresss("plugin.group-code.api.group-code.get-share-poster");
        a._postNetWork({
            url: o,
            data: {
                id: this.data.id,
                ingress: "weChatApplet"
            },
            success: function(t) {
                var a = t.data;
                wx.hideLoading({
                    success: function(t) {}
                }), 1 == a.result ? e.setData({
                    minImga: a.data.image_url,
                    base: a.data.base64Image,
                    shareBox: !0
                }) : (wx.showToast({
                    title: a.msg,
                    icon: "none"
                }), console.log(a.msg));
            }
        });
    },
    taplong: function(t) {
        wx.previewImage({
            current: this.data.info.code_url_img,
            urls: [ this.data.info.code_url_img ]
        });
    },
    explain: function() {
        this.setData({
            showTwo: !0
        });
    },
    service: function() {
        this.setData({
            showOne: !0
        });
    },
    CloseBtn: function() {
        this.setData({
            showOne: !1,
            showTwo: !1,
            shareBox: !1
        });
    },
    tapSave: function() {
        var t = this.data.minImga;
        wx.previewImage({
            current: t,
            urls: [ t ]
        });
    },
    saveImg: function() {
        wx.getSetting({
            success: function(t) {
                t.authSetting["scope.writePhotosAlbum"] || wx.authorize({
                    scope: "scope.writePhotosAlbum",
                    success: function() {
                        console.log("授权成功");
                    }
                });
            }
        });
        var t = this.data.minImga;
        wx.downloadFile({
            url: t,
            success: function(t) {
                console.log(t), wx.saveImageToPhotosAlbum({
                    filePath: t.tempFilePath,
                    success: function(t) {
                        wx.showToast({
                            title: "保存成功",
                            icon: "none",
                            duration: 2e3
                        });
                    },
                    fail: function(t) {
                        console.log(t), "saveImageToPhotosAlbum:fail auth deny" === t.errMsg && (console.log("当初用户拒绝，再次发起授权"), 
                        wx.openSetting({
                            success: function(t) {
                                t.authSetting["scope.writePhotosAlbum"] ? wx.showToast({
                                    icon: "none",
                                    title: "获取权限成功,再次长按保存图片",
                                    duration: 1500
                                }) : wx.showToast({
                                    icon: "none",
                                    title: "获取权限失败,保存图片需要用户授权",
                                    duration: 1500
                                });
                            }
                        }));
                    },
                    complete: function(t) {
                        console.log(t);
                    }
                });
            }
        });
    },
    onReady: function() {},
    onHide: function() {},
    onUnload: function() {
        var t = getCurrentPages();
        t[t.length - 3] && "packageA/detail_v2/detail_v2" == t[t.length - 3].route && wx.navigateBack({
            delta: 1
        });
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: this.data.info.group_code.code_name,
            path: "/packageE/groupCode/groupCodeLabel/groupCodeLabel?id=" + this.data.id
        };
    },
    getData: function() {
        var t = this, e = a.getNetAddresss("plugin.group-code.api.group-code.get-group-code-data");
        a._getNetWork({
            url: e,
            data: {
                id: this.data.id,
                label: this.data.label,
                longitude: this.data.longitude,
                latitude: this.data.latitude
            },
            success: function(a) {
                var e = a.data;
                if (e.data && e.data.status) {
                    var o = e.data.auth_data;
                    t.setData({
                        openAuthData: o,
                        showAuthDialog: !0
                    });
                } else 1 == e.result ? (e.data.data.group_code && e.data.data.group_code.explain_content && (e.data.data.group_code.explain_content = e.data.data.group_code.explain_content.replace(/<img/gi, '<img style="max-width:100%;height:auto;display:block" ')), 
                t.setData({
                    info: e.data.data,
                    group_code: e.data.data.group_code || {}
                }), wx.setNavigationBarTitle({
                    title: e.data.data.group_code.code_name
                })) : wx.showModal({
                    title: "提示",
                    content: e.msg,
                    showCancel: !1,
                    success: function(t) {
                        t.confirm && (getCurrentPages().length <= 1 ? wx.reLaunch({
                            url: "/packageG/index/index"
                        }) : wx.navigateBack({
                            delta: 1
                        }));
                    }
                });
            }
        });
    },
    CloseAuthDialog: function() {
        this.setData({
            showAuthDialog: !1
        }), wx.navigateBack({
            delta: 1
        });
    },
    toHome: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    toMemberGradeList: function() {
        wx.redirectTo({
            url: "/packageB/member/MemberGradeList/MemberGradeList"
        });
    },
    toGroupCodeGoodsList: function() {
        wx.navigateTo({
            url: "/packageE/groupCode/groupCodeGoodsList/groupCodeGoodsList?id=" + this.data.id
        });
    }
});